package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import ${cfg.pageRespImport};
import ${cfg.respPackage}.${entity}VO;
import ${cfg.reqPackage}.${entity}QryReq;
import ${cfg.reqPackage}.${entity}AddReq;
import ${cfg.reqPackage}.${entity}UpdateReq;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    @Override
    public ${cfg.pageClass}<${entity}VO> pageExt(${cfg.pageClass} page, ${entity}QryReq req){

        ${cfg.pageClass}<${entity}> entityPage = page(page,Wrappers.<${entity}>lambdaQuery());

        ${cfg.pageClass}<${entity}VO> resultPage = new ${cfg.pageClass}(page.getCurrent(),page.getSize(),entityPage.getTotal());
        resultPage.setRecords(entityPage.getRecords().stream().map(e->{
            ${entity}VO vo = new ${entity}VO();
            BeanUtils.copyProperties(e,vo);
            return vo;
        }).collect(Collectors.toList()));
        return resultPage;
    }

    @Override
    public List<${entity}VO> listExt(${entity}QryReq req){
        List<${entity}> entityList = list(Wrappers.<${entity}>lambdaQuery());

        return entityList.stream().map(e->{
            ${entity}VO vo = new ${entity}VO();
            BeanUtils.copyProperties(e,vo);
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    public ${entity}VO getByIdExt(String id){
        ${entity}VO vo = new ${entity}VO();
        ${entity} entity = getById(id);
        if (null == entity){
            return vo;
        }
        BeanUtils.copyProperties(entity,vo);
        return vo;
    }

    @Override
    public Boolean saveExt(${entity}AddReq req){
        ${entity} entity = new ${entity}();
        BeanUtils.copyProperties(req,entity);

        return save(entity);
    }

    @Override
    public Boolean updateByIdExt(${entity}UpdateReq req){
        ${entity} entity = new ${entity}();
        BeanUtils.copyProperties(req,entity);

        return updateById(entity);
    }

}
</#if>
